0, In this demonstration, you will learn how to use data access objects, or DAO, to open a Microsoft Jet Database and retrieve a recordset.
15, With my application I can view part of the Employees table from the Northwind database.
23, I can move to the next employee by clicking this command button, and I can skip to the last employee by clicking this command button.
34, Notice, that if I try to move past the last employee, I am warned that this is the last record.
41, I can move to the previous employee by clicking this command button, and I can skip to the first employee by clicking this command button.
53, Again, I am warned if I try to move past the first employee.
61, Let's go ahead and take a look at the code for my application.
65, In the General Declaration section in my application, I declare a variable for the database and a variable for the recordset.
77, In the Load event for this form, I use the OpenDatabase method to set an object variable to the Northwind database.
85, I also use the OpenRecordset method to set an object variable to the Employees table.
91, Notice that I check to see if the EOF and BOF values are true.
97, If they are true, my recordset contains no records and I warn the user appropriately.
102, If my recordset does, however, contain records, I run the FillFields procedure.
109, The FillFields procedure does nothing more than place the appropriate values from my recordset in my form's text boxes.
124, The code for the command button that skips to the first record uses the MoveFirst method and then runs the FillFields procedure.
138, Similarly, the code for the command button that skips to the last record, uses the MoveLast method, and then runs the FillFields procedure.
154, The code for the command button that moves to the next record uses the MoveNext method and then checks to see 165, if the EOF property is true.
165, If so, the MoveLast method is used and a warning message is displayed to the user.
175, If the EOF property is not true, the FillFields procedure is run.
187, In the same manner I check for the end of file when the Move Next command button is clicked, when the user clicks the Move Previous command button, I check to see if the BOF property is true.
201, If so, the MoveFirst method is used and a warning message is displayed.
212, If not, the FillFields procedure is run.
222, Finally, I placed code in the form's Unload event to close the database when the user closes the form.
231, So, in this demonstration, we've taken a look at how to open a Microsoft Jet database and retrieve a recordset using DAO.